import { PokerConfig } from "../config/PokerConfig";
import PokerItem from "./PokerItem";
import { Node, Animation } from 'cc'

export default class PokerArray {

    readonly pokerIsChain: boolean;
    readonly pokerColor: Set<boolean>;
    readonly pokerType: Set<number>;
    readonly pokerEnum: PokerConfig.EnumPoker[];

    constructor(public readonly pokers: PokerItem[], public readonly replaceState: boolean) {
        //进行初步的筛查
        this.pokerEnum = pokers.map(v => v.getPoker());
        this.pokerIsChain = PokerConfig.pokerIsChain(this.pokerEnum);
        this.pokerColor = PokerConfig.pokerColor(this.pokerEnum);
        this.pokerType = PokerConfig.pokerType(this.pokerEnum);
    }


    length() {
        return this.pokers.length
    }

    name() {
        return `Layout-[${this.pokers.map(v => v.pokerIntensify.poker).join('-')}]`
    }

    count() {
        return this.pokers.reduce<number>((pre, value) => {
            return pre + PokerConfig.pokerNumber(value.getPoker());
        }, 0)
    }

    toString() {
        return `(${this.pokers.map(v => PokerConfig.pokerIcon(v.getPoker())).join(',')})`
    }

    changeActive() {
        const animal = this.pokers.map(v => {
            return new Promise(() => {
                //添加一个动画 poker 需要挑一下, 然后顶起一个 当前的效果
                // 如果是同花 , 则显示顶起当前的花色
                // 如果是同色, 则显示当前的颜色
                // 如果是链子,则显示当前的链子图标
                // 如果是对子,则显示当前的对子图标

                // poker 调一下,达到最高(call),显示一个 色块,并且当回落后(call),色块变成能量 输送到上方的数值条中,当进入数值条后(call),数字进行变化
                const anima = v.pokerNode.getComponent(Animation);
                if (!anima) {
                    return;
                }

                anima.play('PokerActive')
            })
        })
        return Promise.all(animal)
    }
}